package com.woniuxy.common;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.woniuxy.dto.CarYearlyInspectionDto;
import com.woniuxy.service.CarYearlyInspectionService;

import java.util.ArrayList;
import java.util.List;

public class CarYearlyInspectionExcelListener extends AnalysisEventListener<CarYearlyInspectionDto> {

    private CarYearlyInspectionService carYearlyInspectionService;

    public CarYearlyInspectionExcelListener(CarYearlyInspectionService carYearlyInspectionService) {
        this.carYearlyInspectionService = carYearlyInspectionService;
    }

    //创建一个集合保存所有导入的数据
    List<CarYearlyInspectionDto> carYearlyInspectionList= new ArrayList<>();
    @Override
    public void invoke(CarYearlyInspectionDto carYearlyInspectionDto, AnalysisContext analysisContext) {
        //每条数据添加到集合中
        carYearlyInspectionList.add(carYearlyInspectionDto);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        //写入到数据库中
        rowCount = carYearlyInspectionService.insertBatch(carYearlyInspectionList);
    }
    //影响行数
    private int rowCount;
    //获取导入的行数
    public int getRowCount() {
        return this.rowCount;
    }
}
